<?php

namespace app\admin\controller\store;

use app\common\controller\AdminController;
use app\common\service\store\CommentService;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;

/**
 * @ControllerAnnotation(title="goods_comment")
 */
class Comment extends AdminController
{

    use \app\admin\traits\Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new \app\admin\model\store\GoodsComment();
        
    }

    public function index()
    {
        if ($this->request->isAjax()) {
            if (input('selectFields')) {
                return $this->selectList();
            }
            list($page, $limit, $where) = $this->buildTableParames();
            $data = CommentService::commentInfo($page,$limit,$where);
            return json($data);
        }
        return $this->fetch();
    }

    public function edit($id)
    {
        $row = $this->model->find($id);
        empty($row) && $this->error('数据不存在');
        if ($this->request->isAjax()) {
            $post = $this->request->post();
            $rule = [];
            $this->validate($post, $rule);
            $save = CommentService::commentReply($id,$post,$row);
            $save ? $this->success('回复成功') : $this->error('回复失败');
        }
        $this->assign('row', $row);
        return $this->fetch();
    }




    
}